<?php
include_once("../metier/question.dao.php");
include_once("../metier/question.class.php");
header("Content-Type: text/plain");

$db = new myPDO("127.0.0.1", "root", "", 0);
$questionDAO = new QuestionDAO();

$idCat = (isset($_GET["cat"])) ? $_GET["cat"] : NULL;
if (($idCat!="all") && ($idCat!=null)) {
	$question = new Question(0, "", null, 0, $idCat);
	$tab = $questionDAO->findQuestionsByCategorie($question, $db);
}
else {
	$tab = $questionDAO->findAllQuestions($db);
}

echo "<?xml version='1.0' encoding='UTF-8'?> \n\r" ;
echo "<listeDeQuestions>"."\n\r" ;
foreach($tab as $ligne) {
	echo "\t"."<question>"."\n\r" ;
	echo "\t\t"."<identifiant>"."\n\r\t\t\t".$ligne->getId()."\n\r\t\t"."</identifiant>"."\n\r";
	echo "\t\t"."<libelle>"."\n\r\t\t\t".$ligne->getLibelle()."\n\r\t\t"."</libelle>"."\n\r";
	echo "\t\t"."<indiceBR>"."\n\r\t\t\t".$ligne->getIndiceBonneReponse()."\n\r\t\t"."</indiceBR>"."\n\r";
	echo "\t\t"."<categorie>"."\n\r\t\t\t".$ligne->getCategorie()."\n\r\t\t"."</categorie>"."\n\r";
	echo "\t"."</question>"."\n\r";
}
echo "</listeDeQuestions>"."\n\r" ;
?>